package com.chinaedu.oc.sdk.util;

import java.util.Map;


import com.chinaedu.oc.sdk.bo.Sign;
import com.chinaedu.oc.sdk.result.Result;

public class CheckSign {
	
	public static Long timeOut = 5*60*1000L;
		
	/**
	 * 检查签名
	 * @Description: TODO
	 * @param @param sign 签名
	 * @param @param key 秘钥
	 * @param @param mi 时间
	 * @param @param obj 入参
	 * @param @return    
	 * @return Result    返回类型 
	 * @throws
	 */
	public static Result Check(String sign, String key, Long mi, Object obj) {
		
		Result r = new Result();
		
		
		CreateSign cs = new CreateSign();
		Sign s = cs.createSign(key, obj, mi);
		
		
		
		if(System.currentTimeMillis() - mi > timeOut) {
			r.setResult(Result.CODE_FAIL_TIME_OUT);
			r.setMsg("接口超时");
			
			return r;
		}
		String si = s.getSign();
		if(!si.equals(sign)) {
			r.setResult(Result.CODE_FAIL_SIGN_ERROR);
			r.setMsg("签名错误");
			
			return r;
		}
		
		r.setResult(Result.CODE_SUCCESS);
		r.setMsg("成功");
		
		return r;
	}
}
